﻿
using System.Collections.Generic;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;
using HuaCheng.Model;
using System;
namespace HuaCheng.Controller
{
    public class CorFacControl
    {
        /// <summary>
        /// 根据校正因子列表生成TreeList
        /// </summary>
        /// <param name="stepList"></param>
        /// <param name="treeList"></param>
        /// <returns></returns>
        public static TreeList SetTreeListByCorrectionFactorList(List<CorrectionFactor> correctionFactorList, TreeList treeList)
        {
            treeList.ClearNodes();
            //遍历工步信息列表
            for (int i = 0; i < correctionFactorList.Count; i++)
            {
                CorrectionFactor correctionFactor = correctionFactorList[i];
                treeList = SetTreeListNodeByCorrectionFactor(correctionFactor, treeList, i);
            }
            return treeList;
        }
        /// <summary>
        /// 根据SlopeStep对象生成TreeList节点
        /// </summary>
        /// <param name="slopeStep"></param>
        /// <param name="treeList"></param>
        /// <param name="i"></param>
        /// <returns></returns>
        private static TreeList SetTreeListNodeByCorrectionFactor(CorrectionFactor correctionFactor, TreeList treeList, int i)
        {
            //新增表节点
            TreeListNode tmpNode = treeList.Nodes.Add();
            //获取slopeStep属性
            Type type = correctionFactor.GetType();
            for (int j = 0; j < treeList.Columns.Count; j++)
            {
                if (type.GetProperty(treeList.Columns[j].FieldName).GetValue(correctionFactor) != null)
                {
                    treeList.SetRowCellValue(tmpNode, treeList.Columns[j], Convert.ToString(type.GetProperty(treeList.Columns[j].FieldName).GetValue(correctionFactor)));
                }
            }
            treeList.SetNodeIndex(tmpNode, i);
            return treeList;
        }
    }
}
